a11y: Add _gtk_cell_accessible_set_cell_data()
authorBenjamin Otte <otte@redhat.com>
Wed, 23 Nov 2011 16:35:00 +0000 (17:35 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 24 Nov 2011 17:29:45 +0000 (18:29 +0100)
See the function documentation for details.

Also included is the implementation for the treeview, but no users yet.

gtk/a11y/gtkcellaccessible.c
gtk/a11y/gtkcellaccessible.h
gtk/a11y/gtkcellaccessibleparent.c
gtk/a11y/gtkcellaccessibleparent.h
gtk/a11y/gtktreeviewaccessible.c

index fdccd19ae41a91caaa337d287ece36d059f423e8..bc503a9c27e0907f79c4219cfc6b5b4fbc548a83 100644 (file)
@@ -421,3 +421,27 @@ atk_component_interface_init (AtkComponentIface *iface)
   iface->get_extents = gtk_cell_accessible_get_extents;
   iface->grab_focus = gtk_cell_accessible_grab_focus;
 }
+
+/**
+ * _gtk_cell_accessible_set_cell_data:
+ * @cell: a #GtkCellAccessible
+ *
+ * Sets the cell data to the row used by @cell. This is useful in
+ * particular if you want to work with cell renderers.
+ *
+ * Note that this function is potentially slow, so be careful.
+ **/
+void
+_gtk_cell_accessible_set_cell_data (GtkCellAccessible *cell)
+{
+  AtkObject *parent;
+
+  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
+
+  parent = gtk_widget_get_accessible (cell->widget);
+  if (parent == NULL)
+    return;
+
+  _gtk_cell_accessible_parent_set_cell_data (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
+}
+
index ceab22295862f991c6467f2c29f63120a4455783..823ae8dfbc92845209ec35d1e8bf9b07f8811551 100644 (file)
@@ -50,6 +50,8 @@ struct _GtkCellAccessibleClass
 
 GType    _gtk_cell_accessible_get_type      (void);
 
+void     _gtk_cell_accessible_set_cell_data (GtkCellAccessible *cell);
+
 void     _gtk_cell_accessible_initialise    (GtkCellAccessible *cell,
                                              GtkWidget         *widget,
                                              AtkObject         *parent);
index a05aaa1340209119e4efc5236ec9045e969e435e..76c6b76411e25676aaddeb63b666070c13b48960 100644 (file)
@@ -111,3 +111,19 @@ _gtk_cell_accessible_parent_get_child_index (GtkCellAccessibleParent *parent,
   else
     return -1;
 }
+
+void
+_gtk_cell_accessible_parent_set_cell_data (GtkCellAccessibleParent *parent,
+                                           GtkCellAccessible       *cell)
+{
+  GtkCellAccessibleParentIface *iface;
+
+  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE_PARENT (parent));
+  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
+
+  iface = GTK_CELL_ACCESSIBLE_PARENT_GET_IFACE (parent);
+
+  if (iface->set_cell_data)
+    (iface->set_cell_data) (parent, cell);
+}
+
index f4e1ea28b85cf0e7aecb9cf2152dce7d8ad4e0b6..797a7842671a7cbd5510e08f6314b25360666e31 100644 (file)
@@ -60,6 +60,9 @@ struct _GtkCellAccessibleParentIface
                                  GtkCellAccessible       *cell);
   int      ( *get_child_index)  (GtkCellAccessibleParent *parent,
                                  GtkCellAccessible       *cell);
+  void     ( *set_cell_data)    (GtkCellAccessibleParent *parent,
+                                 GtkCellAccessible       *cell);
+
 };
 
 GType    _gtk_cell_accessible_parent_get_type         (void);
@@ -78,6 +81,8 @@ gboolean _gtk_cell_accessible_parent_grab_focus       (GtkCellAccessibleParent *
                                                        GtkCellAccessible       *cell);
 int      _gtk_cell_accessible_parent_get_child_index  (GtkCellAccessibleParent *parent,
                                                        GtkCellAccessible       *cell);
+void     _gtk_cell_accessible_parent_set_cell_data    (GtkCellAccessibleParent *parent,
+                                                       GtkCellAccessible       *cell);
 
 G_END_DECLS
 
index 0589c4ae2d40d4490faedc092fe5b5166f132405..d8bf3d61ca0016ac8b83c19955d3817fdd8357fa 100644 (file)
@@ -1516,6 +1516,51 @@ gtk_tree_view_accessible_get_child_index (GtkCellAccessibleParent *parent,
   return cell_info_get_index (tree_view, cell_info);
 }
 
+static void
+gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
+                                        GtkCellAccessible       *cell)
+{
+  GtkTreeViewAccessibleCellInfo *cell_info;
+  GtkTreeView *treeview;
+  gboolean is_expander, is_expanded;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+
+  cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
+  if (!cell_info)
+    return;
+
+  treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
+  model = gtk_tree_view_get_model (treeview);
+
+  if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
+      cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
+    {
+      is_expander = TRUE;
+      is_expanded = cell_info->node->children != NULL;
+    }
+  else
+    {
+      is_expander = FALSE;
+      is_expanded = FALSE;
+    }
+
+  path = cell_info_get_path (cell_info);
+  if (path == NULL ||
+      !gtk_tree_model_get_iter (model, &iter, path))
+    {
+      /* We only track valid cells, this should never happen */
+      g_return_if_reached ();
+    }
+
+  gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
+                                           model,
+                                           &iter,
+                                           is_expander,
+                                           is_expanded);
+}
+
 static void
 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
 {
@@ -1523,6 +1568,7 @@ gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
   iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
   iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
   iface->get_child_index = gtk_tree_view_accessible_get_child_index;
+  iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
 }
 
 /* signal handling */